﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:VisualTools.Controls"
                    xmlns:converters="clr-namespace:VisualTools.Controls.Converters">

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <converters:CanResizeAndWindowState2VisibilityMultiConverter x:Key="CanResizeAndWindowState2VisibilityMultiConverter" />

    <SolidColorBrush x:Key="HoverYellowBorder" Color="#FFFFC52C" />
    <SolidColorBrush x:Key="PressOrangeBorder" Color="#FF70612D" />    
    
    <LinearGradientBrush x:Key="HoverYellowBackground" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FFFFFCC0" Offset="0.492"/>
        <GradientStop Color="#FFFFE22C" Offset="0.5"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="PressOrangeBackground" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FFFFDD64" Offset="0.492"/>
        <GradientStop Color="#FFFFC52C" Offset="0.5"/>
        <GradientStop Color="#FFFFDD64" Offset="0.139"/>
        <GradientStop Color="#FFC3A84A" Offset="0.036"/>
        <GradientStop Color="#FFFFC52C" Offset="0.586"/>
        <GradientStop Color="#FFFFE9B0" Offset="0.948"/>
    </LinearGradientBrush>
    
    <Style x:Key="LooklessButton" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border BorderBrush="Transparent" Margin="0,2,2,2" BorderThickness="1" CornerRadius="2" x:Name="buttonBorder">
                        <ContentPresenter />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Border.IsMouseOver" Value="True">
                            <Setter TargetName="buttonBorder" Property="Border.Background" Value="{StaticResource HoverYellowBackground}" />
                            <Setter TargetName="buttonBorder" Property="Border.BorderBrush" Value="{StaticResource HoverYellowBorder}" />
                        </Trigger>
                        <Trigger Property="Button.IsPressed" Value="True">
                            <Setter TargetName="buttonBorder" Property="Border.Background" Value="{StaticResource PressOrangeBackground}" />
                            <Setter TargetName="buttonBorder" Property="Border.BorderBrush" Value="{StaticResource PressOrangeBorder}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="rightSideTemplate">
        <Rectangle Cursor="SizeWE" Margin="0,9,4,9" Width="5" Fill="Transparent" HorizontalAlignment="Right" />
    </ControlTemplate>

    <ControlTemplate x:Key="bottomSideTemplate">
        <Rectangle Cursor="SizeNS" Margin="9,0,9,4" Height="5" Fill="Transparent" VerticalAlignment="Bottom" />
    </ControlTemplate>
    
    <ControlTemplate x:Key="cornerTemplate">
        <Rectangle Panel.ZIndex="10" Cursor="SizeNWSE" Margin="0,0,0,0" Height="10" Width="10" Fill="Transparent" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
    </ControlTemplate>

    <Style x:Key="BlueTheme" TargetType="{x:Type local:WpfWindow}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:WpfWindow}">
                    <Grid>
                        <!--Shadow-->
                        <!--Actual Window Border-->
                        <Border Margin="0" x:Name="WindowBorder" BorderThickness="1" CornerRadius="4">
                            <Border.BorderBrush>
                                <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="#FFA3C5F2" />
                            </Border.BorderBrush>
                            <Border.Background>
                                <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="#FFE6FEFD" />
                            </Border.Background>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <!--Title Bar-->
                                <Border CornerRadius="4,4,0,0" BorderThickness="1,1,1,0" Grid.Row="0" x:Name="TitleBar">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="White" />
                                    </Border.BorderBrush>
                                    <Border.Background>
                                        <LinearGradientBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#00FFFFFF" Offset=".5"/>
                                            <GradientStop Color="#6283A5D2" Offset=".5"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <Border.ContextMenu>
                                        <ContextMenu x:Name="WindowContextMenu">
                                            <MenuItem x:Name="RestoreMenuItem" 
                                                      IsEnabled="{TemplateBinding CanNormalize}"
                                                      Header="Restore">
                                                
                                            </MenuItem>
                                            <MenuItem x:Name="MinimizeMenuItem" 
                                                      IsEnabled="{TemplateBinding CanMinimize}"
                                                      Header="Minimize">
                                                
                                            </MenuItem>
                                            <MenuItem x:Name="MaximizeMenuItem" 
                                                      IsEnabled="{TemplateBinding CanMaximize}"
                                                      Header="Maximize">
                                                
                                            </MenuItem>
                                            <Separator />
                                            <MenuItem x:Name="CloseMenuItem"
                                                      IsEnabled="{TemplateBinding CanClose}"
                                                      Header="Close" InputGestureText="Alt + F4" />
                                        </ContextMenu>
                                    </Border.ContextMenu>
                                    <Grid>
                                        <!--Title-->
                                        <DockPanel Margin="5,0,0,0" LastChildFill="False" VerticalAlignment="Top" HorizontalAlignment="Left">
                                            <Image Margin="0,5,0,0" Width="24" Height="24" x:Name="WindowIcon" Source="{TemplateBinding Icon}" VerticalAlignment="Center" HorizontalAlignment="Left" />
                                            <ContentControl x:Name="WindowTitle" Foreground="Navy" VerticalAlignment="Center" Margin="10,0,0,0" Content="{TemplateBinding Title}" />
                                        </DockPanel>
                                        <!--System Buttons-->
                                        <DockPanel LastChildFill="False" VerticalAlignment="Top" HorizontalAlignment="Right">
                                            <Button x:Name="MinimizeButton" 
                                                    Visibility="{Binding Path=CanMinimize, Mode=TwoWay,
                                                    RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}, 
                                                    Converter={StaticResource BooleanToVisibilityConverter}}" 
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/minimize_window_blue.png" />
                                            </Button>
                                            <Button x:Name="MaximizeButton" 
                                                    Visibility="{Binding Path=CanMaximize, Mode=TwoWay,
                                                    RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}, 
                                                    Converter={StaticResource BooleanToVisibilityConverter}}" 
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/maximize_window_blue.png" />
                                            </Button>
                                            <Button x:Name="NormalizeButton" 
                                                    Visibility="{Binding Path=CanNormalize, Mode=TwoWay,
                                                    RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}, 
                                                    Converter={StaticResource BooleanToVisibilityConverter}}" 
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/normal_window_blue.png" />
                                            </Button>
                                            <Button x:Name="CloseButton" 
                                                    Visibility="{TemplateBinding CanClose, Converter={StaticResource BooleanToVisibilityConverter}}"
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/close_window_blue.png" />
                                            </Button>
                                        </DockPanel>
                                    </Grid>
                                </Border>
                                <Border CornerRadius="0,0,4,4" BorderThickness="1,0,1,1" Grid.Row="1"
                                        x:Name="WhiteContentBorder">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="White" />
                                    </Border.BorderBrush>
                                    <Border.Background>
                                        <LinearGradientBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#6283A5D2" Offset="0.0"/>
                                            <GradientStop Color="#00FFFFFF" Offset="1.0"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <Border BorderThickness="1" Margin="3,0,3,3" x:Name="ContentBorderOutside">
                                        <Border.BorderBrush>
                                            <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="White" />
                                        </Border.BorderBrush>
                                        <Border BorderThickness="1" Background="{TemplateBinding Background}" x:Name="ContentBorderInside">
                                            <Border.BorderBrush>
                                                <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="#FF83A5D2" />
                                            </Border.BorderBrush>
                                            <ContentPresenter />
                                        </Border>
                                    </Border>
                                </Border>
                            </Grid>
                        </Border>
                        <!--Resize Thumbs-->
                        <Thumb x:Name="RightSideThumb" 
                               Template="{StaticResource rightSideTemplate}">
                            <Thumb.Visibility>
                                <MultiBinding Converter="{StaticResource CanResizeAndWindowState2VisibilityMultiConverter}" ConverterParameter="Maximized">
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="ResizeMode" />
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="WindowState" />
                                </MultiBinding>
                            </Thumb.Visibility>
                        </Thumb>
                        <Thumb x:Name="BottomSideThumb" 
                               Template="{StaticResource bottomSideTemplate}">
                            <Thumb.Visibility>
                                <MultiBinding Converter="{StaticResource CanResizeAndWindowState2VisibilityMultiConverter}" ConverterParameter="Maximized">
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="ResizeMode" />
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="WindowState" />
                                </MultiBinding>
                            </Thumb.Visibility>
                        </Thumb>
                        <Thumb x:Name="CornerThumb" 
                               Template="{StaticResource cornerTemplate}">
                            <Thumb.Visibility>
                                <MultiBinding Converter="{StaticResource CanResizeAndWindowState2VisibilityMultiConverter}" ConverterParameter="Maximized">
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="ResizeMode" />
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="WindowState" />
                                </MultiBinding>
                            </Thumb.Visibility>
                        </Thumb>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="BlackTheme" TargetType="{x:Type local:WpfWindow}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:WpfWindow}">
                    <Grid>
                        <!--Shadow-->
                        <!--Actual Window Border-->
                        <Border Margin="0" x:Name="WindowBorder" BorderThickness="1" CornerRadius="4">
                            <Border.BorderBrush>
                                <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="#FF000000" />
                            </Border.BorderBrush>
                            <Border.Background>
                                <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="#FF696969" />
                            </Border.Background>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <!--Title Bar-->
                                <Border CornerRadius="4,4,0,0" BorderThickness="1,1,1,0" Grid.Row="0" x:Name="TitleBar">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="Silver" />
                                    </Border.BorderBrush>
                                    <Border.Background>
                                        <LinearGradientBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#00FFFFFF" Offset=".5"/>
                                            <GradientStop Color="#62232323" Offset=".5"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <Border.ContextMenu>
                                        <ContextMenu x:Name="WindowContextMenu">
                                            <MenuItem x:Name="RestoreMenuItem" 
                                                      IsEnabled="{TemplateBinding CanNormalize}"
                                                      Header="Restore">

                                            </MenuItem>
                                            <MenuItem x:Name="MinimizeMenuItem" 
                                                      IsEnabled="{TemplateBinding CanMinimize}"
                                                      Header="Minimize">

                                            </MenuItem>
                                            <MenuItem x:Name="MaximizeMenuItem" 
                                                      IsEnabled="{TemplateBinding CanMaximize}"
                                                      Header="Maximize">

                                            </MenuItem>
                                            <Separator />
                                            <MenuItem x:Name="CloseMenuItem"
                                                      IsEnabled="{TemplateBinding CanClose}"
                                                      Header="Close" InputGestureText="Alt + F4" />
                                        </ContextMenu>
                                    </Border.ContextMenu>
                                    <Grid>
                                        <!--Title-->
                                        <DockPanel Margin="5,0,0,0" LastChildFill="False" VerticalAlignment="Top" HorizontalAlignment="Left">
                                            <Image Margin="0,5,0,0" Width="24" Height="24" x:Name="WindowIcon" Source="{TemplateBinding Icon}" VerticalAlignment="Center" HorizontalAlignment="Left" />
                                            <ContentControl x:Name="WindowTitle" Foreground="White" VerticalAlignment="Center" Margin="10,0,0,0" Content="{TemplateBinding Title}" />
                                        </DockPanel>
                                        <!--System Buttons-->
                                        <DockPanel LastChildFill="False" VerticalAlignment="Top" HorizontalAlignment="Right">
                                            <Button x:Name="MinimizeButton"
                                                    Visibility="{Binding Path=CanMinimize, Mode=TwoWay,
                                                    RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}, 
                                                    Converter={StaticResource BooleanToVisibilityConverter}}" 
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/minimize_window_blue.png" />
                                            </Button>
                                            <Button x:Name="MaximizeButton" 
                                                    Visibility="{Binding Path=CanMaximize, Mode=TwoWay,
                                                    RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}, 
                                                    Converter={StaticResource BooleanToVisibilityConverter}}" 
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/maximize_window_blue.png" />
                                            </Button>
                                            <Button x:Name="NormalizeButton" 
                                                    Visibility="{Binding Path=CanNormalize, Mode=TwoWay,
                                                    RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}, 
                                                    Converter={StaticResource BooleanToVisibilityConverter}}" 
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/normal_window_blue.png" />
                                            </Button>
                                            <Button x:Name="CloseButton" 
                                                    Visibility="{TemplateBinding CanClose, Converter={StaticResource BooleanToVisibilityConverter}}"
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/close_window_blue.png" />
                                            </Button>
                                        </DockPanel>
                                    </Grid>
                                </Border>
                                <Border CornerRadius="0,0,4,4" BorderThickness="1,0,1,1" Grid.Row="1"
                                        x:Name="WhiteContentBorder">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="Silver" />
                                    </Border.BorderBrush>
                                    <Border.Background>
                                        <LinearGradientBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#62232323" Offset=".0"/>
                                            <GradientStop Color="#00FFFFFF" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <Border BorderThickness="1" Margin="3,0,3,3" x:Name="ContentBorderOutside">
                                        <Border.BorderBrush>
                                            <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="Silver" />
                                        </Border.BorderBrush>
                                        <Border BorderThickness="1" Background="{TemplateBinding Background}" x:Name="ContentBorderInside">
                                            <Border.BorderBrush>
                                                <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="#FF000000" />
                                            </Border.BorderBrush>
                                            <ContentPresenter />
                                        </Border>
                                    </Border>
                                </Border>
                            </Grid>
                        </Border>
                        <!--Resize Thumbs-->
                        <Thumb x:Name="RightSideThumb" 
                               Template="{StaticResource rightSideTemplate}">
                            <Thumb.Visibility>
                                <MultiBinding Converter="{StaticResource CanResizeAndWindowState2VisibilityMultiConverter}" ConverterParameter="Maximized">
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="ResizeMode" />
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="WindowState" />
                                </MultiBinding>
                            </Thumb.Visibility>
                        </Thumb>
                        <Thumb x:Name="BottomSideThumb" 
                               Template="{StaticResource bottomSideTemplate}">
                            <Thumb.Visibility>
                                <MultiBinding Converter="{StaticResource CanResizeAndWindowState2VisibilityMultiConverter}" ConverterParameter="Maximized">
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="ResizeMode" />
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="WindowState" />
                                </MultiBinding>
                            </Thumb.Visibility>
                        </Thumb>
                        <Thumb x:Name="CornerThumb" 
                               Template="{StaticResource cornerTemplate}">
                            <Thumb.Visibility>
                                <MultiBinding Converter="{StaticResource CanResizeAndWindowState2VisibilityMultiConverter}" ConverterParameter="Maximized">
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="ResizeMode" />
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="WindowState" />
                                </MultiBinding>
                            </Thumb.Visibility>
                        </Thumb>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="SilverTheme" TargetType="{x:Type local:WpfWindow}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:WpfWindow}">
                    <Grid>
                        <!--Shadow-->
                        <!--Actual Window Border-->
                        <Border Margin="0" x:Name="WindowBorder" BorderThickness="1" CornerRadius="4">
                            <Border.BorderBrush>
                                <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="DimGray" />
                            </Border.BorderBrush>
                            <Border.Background>
                                <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="LightGray" />
                            </Border.Background>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <!--Title Bar-->
                                <Border CornerRadius="4,4,0,0" BorderThickness="1,1,1,0" Grid.Row="0" x:Name="TitleBar">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="White" />
                                    </Border.BorderBrush>
                                    <Border.Background>
                                        <LinearGradientBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#00FFFFFF" Offset=".5"/>
                                            <GradientStop Color="Silver" Offset=".5"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <Border.ContextMenu>
                                        <ContextMenu x:Name="WindowContextMenu">
                                            <MenuItem x:Name="RestoreMenuItem" 
                                                      IsEnabled="{TemplateBinding CanNormalize}"
                                                      Header="Restore">

                                            </MenuItem>
                                            <MenuItem x:Name="MinimizeMenuItem" 
                                                      IsEnabled="{TemplateBinding CanMinimize}"
                                                      Header="Minimize">

                                            </MenuItem>
                                            <MenuItem x:Name="MaximizeMenuItem" 
                                                      IsEnabled="{TemplateBinding CanMaximize}"
                                                      Header="Maximize">

                                            </MenuItem>
                                            <Separator />
                                            <MenuItem x:Name="CloseMenuItem"
                                                      IsEnabled="{TemplateBinding CanClose}"
                                                      Header="Close" InputGestureText="Alt + F4" />
                                        </ContextMenu>
                                    </Border.ContextMenu>
                                    <Grid>
                                        <!--Title-->
                                        <DockPanel Margin="5,0,0,0" LastChildFill="False" VerticalAlignment="Top" HorizontalAlignment="Left">
                                            <Image Margin="0,5,0,0" Width="24" Height="24" x:Name="WindowIcon" Source="{TemplateBinding Icon}" HorizontalAlignment="Left" />
                                            <ContentControl x:Name="WindowTitle" Foreground="DimGray" VerticalAlignment="Center" Margin="10,0,0,0" Content="{TemplateBinding Title}" />
                                        </DockPanel>
                                        <!--System Buttons-->
                                        <DockPanel LastChildFill="False" VerticalAlignment="Top" HorizontalAlignment="Right">
                                            <Button x:Name="MinimizeButton"
                                                    Visibility="{Binding Path=CanMinimize, Mode=TwoWay,
                                                    RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}, 
                                                    Converter={StaticResource BooleanToVisibilityConverter}}" 
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/minimize_window_blue.png" />
                                            </Button>
                                            <Button x:Name="MaximizeButton" 
                                                    Visibility="{Binding Path=CanMaximize, Mode=TwoWay,
                                                    RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}, 
                                                    Converter={StaticResource BooleanToVisibilityConverter}}" 
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/maximize_window_blue.png" />
                                            </Button>
                                            <Button x:Name="NormalizeButton" 
                                                    Visibility="{Binding Path=CanNormalize, Mode=TwoWay,
                                                    RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}, 
                                                    Converter={StaticResource BooleanToVisibilityConverter}}" 
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/normal_window_blue.png" />
                                            </Button>
                                            <Button x:Name="CloseButton" 
                                                    Visibility="{TemplateBinding CanClose, Converter={StaticResource BooleanToVisibilityConverter}}"
                                                    Style="{StaticResource LooklessButton}">
                                                <Image Stretch="None" Source="pack://application:,,,/VisualTools.Controls;component/Images/close_window_blue.png" />
                                            </Button>
                                        </DockPanel>
                                    </Grid>
                                </Border>
                                <Border CornerRadius="0,0,4,4" BorderThickness="1,0,1,1" Grid.Row="1" x:Name="WhiteContentBorder">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="White" />
                                    </Border.BorderBrush>
                                    <Border.Background>
                                        <LinearGradientBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="Silver" Offset=".0"/>
                                            <GradientStop Color="#00FFFFFF" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <Border BorderThickness="1" Margin="3,0,3,3" BorderBrush="White" x:Name="ContentBorderOutside">
                                        <Border BorderThickness="1" Background="{TemplateBinding Background}" x:Name="ContentBorderInside">
                                            <Border.BorderBrush>
                                                <SolidColorBrush Opacity="{Binding Path=BorderOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}}" Color="Gray" />
                                            </Border.BorderBrush>
                                            <ContentPresenter />
                                        </Border>
                                    </Border>
                                </Border>
                            </Grid>
                        </Border>
                        <!--Resize Thumbs-->
                        <Thumb x:Name="RightSideThumb" 
                               Template="{StaticResource rightSideTemplate}">
                            <Thumb.Visibility>
                                <MultiBinding Converter="{StaticResource CanResizeAndWindowState2VisibilityMultiConverter}" ConverterParameter="Maximized">
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="ResizeMode" />
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="WindowState" />
                                </MultiBinding>
                            </Thumb.Visibility>
                        </Thumb>
                        <Thumb x:Name="BottomSideThumb" 
                               Template="{StaticResource bottomSideTemplate}">
                            <Thumb.Visibility>
                                <MultiBinding Converter="{StaticResource CanResizeAndWindowState2VisibilityMultiConverter}" ConverterParameter="Maximized">
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="ResizeMode" />
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="WindowState" />
                                </MultiBinding>
                            </Thumb.Visibility>
                        </Thumb>
                        <Thumb x:Name="CornerThumb" 
                               Template="{StaticResource cornerTemplate}">
                            <Thumb.Visibility>
                                <MultiBinding Converter="{StaticResource CanResizeAndWindowState2VisibilityMultiConverter}" ConverterParameter="Maximized">
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="ResizeMode" />
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:WpfWindow}, Mode=FindAncestor}" Path="WindowState" />
                                </MultiBinding>
                            </Thumb.Visibility>
                        </Thumb>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>